<?php
/**
 * Created by PhpStorm.
 * User: dung
 * Date: 11/4/14
 * Time: 10:42 AM
 */
namespace Contest;

use BaseController;
use Blog;
use Config;
use Contest;
use Input;
use Lang;
use Redirect;
use Sentry;
use Str;
use Validator;
use Video;
use View;

class HomeController extends BaseController
{
    public function getIndex()
    {
        $data = array();

        $blog = new Blog();
        $data['news'] = $blog->blogHomeContest();
        $data['key'] = Input::get('key', '');
        $data['videos'] = Video::join('users', 'users.id', '=', 'videos.user_id')
            ->select('videos.*', 'users.id as userid', 'users.username')
            ->where('contest_id', '!=', 0)->orderBy('votes', 'DESC')
            ->where(function ($where) use ($data) {
                if ($data['key'] != '')
                    $where->where('title', 'LIKE', '%' . $data['key'] . '%');
            })->paginate(16)->appends(array('key' => $data['key']));
        $data['cEvent'] = Contest::where('status', '=', 'on')->where('parent_id', '=', 0)->where('start', '>=', time())->where('end', '<=', time())->orderBy('start', 'DESC')->first();
        return View::make('contest/home/index', compact('data'));
    }
} 